package com.mgface.framework.configuration;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;

import com.mgface.framework.entity.RandomEntity2;
import com.mgface.framework.utility.StringToDateConverter;

@Configuration
@Order(1)
public class BeansConfiguration {
	private final static Logger log = LogManager.getLogger(BeansConfiguration.class);
	/**
	 * 自定义类型转换Bean配置
	 * 
	 * @return
	 */
	@Bean(name = "conversionService")
	public ConversionService conversionService() {
		log.info(">>>>>>初始化[conversionService],order[1]<<<<<<");
		DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(true);
		conversionService.addConverter(new StringToDateConverter());
		return conversionService;
	}

	@Bean(name = "randomentity2")
	@ConfigurationProperties(locations = {"classpath:/random-number.yml" }, prefix = "random", exceptionIfInvalid = true)
	@Profile("dev") // 任何@Component或@Configuration都能被@Profile标记,从而限制加载它的时机。
	public RandomEntity2 getEntity() {
		return new RandomEntity2();
	}
}
